﻿package com.tangchao.client.sdh.view
{
	import com.tangchao.client.sdh.definition.DFState;
	import com.tangchao.client.sdh.event.PlayEvent;
	import com.tangchao.client.sdh.event.ReadyEvent;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;

	public class ReadyPlay extends MovieClip
	{
		private var _nowState:int=DFState.READY_NO;
		public function ReadyPlay()
		{
			visible = false;
		}
		
		public function set nowState(i:int)
		{
			_nowState=i;
			changeState();
		}
		
		private function changeState()
		{
			switch(_nowState)
			{
				case DFState.READY_NO:
					this.visible=true;
					this.gotoAndStop(1);
					this.btnReady.addEventListener(MouseEvent.CLICK,onReadyClick);
					break;
				case DFState.PLAY_OUT:
					this.visible=true;
					this.gotoAndStop(2);
					//this.btnPrompt.addEventListener(MouseEvent.CLICK,onPromptClick);
					this.btnOutCard.addEventListener(MouseEvent.CLICK,onOutCard);
					break;
				case DFState.PLAY_GAIPAI:
					this.visible=true;
					this.gotoAndStop(3);
					this.btnGaiPai.addEventListener(MouseEvent.CLICK,onGaiPaiClick);
					break;
				default:
					this.visible=false;
					break;
			}
		}
		
		/*
		*点击盖牌按钮
		*/
		private function onGaiPaiClick(e:MouseEvent)
		{
			trace(this, "onGaiPaiClick");
			var evt:PlayEvent=new PlayEvent(PlayEvent.GAIPAI);
			dispatchEvent(evt);
		}
		
		/*
		*点击准备按钮
		*/
		private function onReadyClick(e:MouseEvent)
		{
			var evt:ReadyEvent=new ReadyEvent();
			dispatchEvent(evt);
		}
		
		/*
		*点击提示按钮
		*/
		private function onPromptClick(e:MouseEvent)
		{
			var evt:PlayEvent=new PlayEvent(PlayEvent.Prompt);
			dispatchEvent(evt);
		}
		
		/*
		*点击出牌按钮
		*/
		private function onOutCard(e:MouseEvent)
		{
			var evt:PlayEvent=new PlayEvent(PlayEvent.OUT);
			dispatchEvent(evt);
		}
	}
}